package com.mck.service.impl;

import com.mck.entity.ScoreTotal;
import com.mck.mapper.ScoreTotalMapper;
import com.mck.service.ScoreTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @version 1.0.0
 * @Author mck
 * @Date 2025/4/16 下午12:01
 * @注释
 */
@Service
public class ScoreTotalServiceImpl implements ScoreTotalService {

    @Autowired
    private ScoreTotalMapper scoreTotalMapper;

    // 统计排名
    @Override
    @Transactional
    public void computeScoreTotalRank() {
        scoreTotalMapper.updateTheoryRank();
        scoreTotalMapper.updatePracticeRank();
    }

    // 获取总分
    @Override
    @Cacheable(value = "scoreTotalList", key = "'userId_' + #scoreTotal.userId", unless = "#result.isEmpty()")
    public List<ScoreTotal> getScoreTotalList(ScoreTotal scoreTotal) {
        return scoreTotalMapper.getScoreTotalList(scoreTotal);
    }

    // // 添加总分
    // @Override
    // public void batchUpsertScoreTotal(ScoreTotal scoreTotal) {
    //     scoreTotal.setUpdateTime(LocalDateTime.now());
    //
    //     scoreTotalMapper.batchUpsertScoreTotal(scoreTotal);
    // }

    // // 更新总分
    // @Override
    // public void updateScoreTotal(ScoreTotal scoreTotal) {
    //     scoreTotal.setUpdateTime(LocalDateTime.now());
    //
    //     scoreTotalMapper.updateScoreTotal(scoreTotal);
    // }
}
